/**
 * @file   main.cpp
 * @author Heyu Wang <hywang@walker-9>
 * @date   Tue Dec 15 11:59:06 2020
 * 
 * @brief  A demo from https://cplusplus.com
 * 
 * 
 */


#include <iostream>
using namespace std;

class Polygon {
  private:
    int key;
  protected:
    int width, height;
  public:
    void set_key(int _k) {key = _k;}
    void set_values (int a, int b)
      { width=a; height=b;}
 };

class Rectangle: public Polygon {
  public:
    int area ()
      { return width * height; }
 };

class Triangle: public Polygon {
  public:
    int area ()
      { return width * height / 2; }
  };
  
int main () {
  Rectangle rect;
  Triangle trgl;
  rect.set_values (4,5);   // 直接调用了基类的 public 函数；
  rect.set_key(3);  // 仍然可以通过基类的接口函数，修改基类的 private 成员；
  trgl.set_values (4,5);
  cout << rect.area() << '\n';
  cout << trgl.area() << '\n';
  return 0;
};
